package services

import (
	"go-tool/db/orm_iray_proxy"
	"time"
)

type JobWholeObj struct {
	Timestamp        time.Time `json:"@timestamp"`
	JobID            string    `json:"jobId"`
	FinishedTime     string    `json:"finishedTime"`
	StartTime        string    `json:"startTime"`
	Ts               time.Time `json:"ts"`
	Height           int       `json:"height"`
	LogTopic         string    `json:"log_topic"`
	UploadCost       int       `json:"uploadCost"`
	Status           string    `json:"status"`
	Priority         int       `json:"priority"`
	HostIP           string    `json:"host_ip"`
	Width            int       `json:"width"`
	MaxIterations    int       `json:"maxIterations"`
	SubmitTime       string    `json:"submitTime"`
	Level            string    `json:"level"`
	Success          bool      `json:"success"`
	JobStartTime     string    `json:"job_start_time"`      //任务开始时间
	JobEndTime       string    `json:"job_end_time"`        //任务结束时间
	UploadEndTime    string    `json:"upload_end_time"`     //图片上传结束时间
	RenderType       int       `json:"render_type"`         //渲染类型
	Retries          int       `json:"retries"`             //重试次数
	StrInitStartTime string    `json:"str_init_start_time"` //任务构建开始时间
	StrInitEndTime   string    `json:"str_init_end_time"`   //任务构建结束时间
	StrSwitchTime    string    `json:"str_swith_time"`      //任务场景转换成功时间
	StrSubmitTime    string    `json:"str_submit_time"`     //任务提交IrayServer成功时间
	ConstructIp      string    `json:"construct_ip"`        //构建服ip
	//总时长
	TotalCost int64 `json:"totalCost"`
	//等待构建时长
	ConstructWaitCost int64
	//构建加载时长
	ConstructInitCost int64
	//构建场景转换时长
	ConstructSwithCost int64
	//构建上传iray时长
	ConstructToIrayCost int64
	//iray渲染总时长
	IrayTotalCost int64
	//iray渲染等待时长
	WaitRenderCost int64 `json:"waitRenderCost"`
	//iray渲染时长
	RenderCost int64 `json:"renderCost"`
	//构建完成到图片上传到oss时长
	ConstructUploadCost int64
}

func (e *JobWholeObj) DbJobInfoToJobObj(info orm_iray_proxy.JobInfo) (obj JobWholeObj) {
	obj = JobWholeObj{
		Timestamp:        info.FinishedTime.Time.UTC(),
		JobID:            info.JobId,
		FinishedTime:     info.FinishedTime.Time.Local().Format("2006-01-02 15:04:05"),
		TotalCost:        info.FinishedTime.Time.Local().Unix() - info.SubmitTime.Time.Unix(),
		StartTime:        time.Unix(info.FinishedTime.Time.Unix()-int64(info.RenderTime.Float64), 0).Local().Format("2006-01-02 15:04:05"), //减去渲染时长 rendercost
		Ts:               info.FinishedTime.Time.Local(),
		Height:           info.Height,
		LogTopic:         "cloud-job-stat",
		RenderCost:       int64(info.RenderTime.Float64),
		WaitRenderCost:   info.FinishedTime.Time.Local().Unix() - info.SubmitTime.Time.Unix() - int64(info.RenderTime.Float64),
		UploadCost:       0,
		Status:           "jobStat",
		Priority:         info.Priority,
		HostIP:           info.Ip.String,
		Width:            info.Width,
		MaxIterations:    info.MaxIterations,
		SubmitTime:       info.SubmitTime.Time.Local().Format("2006-01-02 15:04:05"),
		Level:            "info",
		Success:          true,
		JobStartTime:     info.JobStartTime.Time.Local().Format("2006-01-02 15:04:05"),
		JobEndTime:       info.JobEndTime.Time.Local().Format("2006-01-02 15:04:05"),
		UploadEndTime:    info.UploadEndTime.Time.Local().Format("2006-01-02 15:04:05"),
		RenderType:       0,
		Retries:          0,
		StrInitStartTime: info.StrInitStartTime.Time.Local().Format("2006-01-02 15:04:05"),
		StrInitEndTime:   info.StrInitEndTime.Time.Local().Format("2006-01-02 15:04:05"),
		StrSwitchTime:    info.StrSwitchTime.Time.Local().Format("2006-01-02 15:04:05"),
		StrSubmitTime:    info.StrSubmitTime.Time.Local().Format("2006-01-02 15:04:05"),
		ConstructIp:      info.ConstructIp.String,
	}
	return
}
